package top.xbaoziplus.company.common;


import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import lombok.Data;

/**
 * @author xBaozi
 * @version 1.0
 * @classname Result
 * @description 统一返回结果集
 * @date 2022/6/29 9:31
 */
@Data
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    public static Integer ok = 200;
    public static Integer fail = 201;

    /**
     * @description 成功示例
     * @author xBaozi
     * @date 9:43 2022/6/29
     * @param data  成功返回结果
     **/
    public static <T> Result<T> success(T data, String msg) {
        Result<T> result = new Result<T>();
        result.setCode(ok);
        result.setData(data);
        result.setMsg(msg);
        return result;
    }

    /**
     * @description 成功示例，只返回信息
     * @author kang
     * @date 2022/6/29 下午 3:17
     * @param msg 返回到前端的信息
     */
    public static <T> Result<T> success(String msg) {
        Result<T> result = new Result<T>();
        result.setCode(ok);
        result.setData(null);
        result.setMsg(msg);
        return result;
    }


    /**
     * @description 失败示例
     * @author xBaozi
     * @date 9:44 2022/6/29
     * @param msg   失败信息
     **/
    public static <T> Result<T> fail(String msg) {
        Result<T> result = new Result<T>();
        result.msg = msg;
        result.code = fail;
        return result;
    }
}
